#pragma once

#include <GLcommon/GLDispatch.h>
#include <GLcommon/GLESpointer.h>
#include <GLcommon/GLESbuffer.h>
#include <GLcommon/GLEScontext.h>
#include <map>
#include <vector>
#include <string>
#include <list>


typedef std::map<GLfloat,std::vector<int> > PointSizeIndices;

class GLEScmContext: public GLEScontext
{
public:
    void init();
    GLEScmContext();

    void setActiveTexture(GLenum tex);
    void  setClientActiveTexture(GLenum tex);
    GLenum  getActiveTexture() { return GL_TEXTURE0 + m_activeTexture;};
    GLenum  getClientActiveTexture() { return GL_TEXTURE0 + m_clientActiveTexture;};
    void insertTextures(GLuint tex) {m_textures.push_back(tex); }
    void insertBuffers(GLuint buf)  { m_buffers.push_back(buf); }
    void insertFramebufffers(GLuint frameBuf) { m_framebuffers.push_back(frameBuf);}
    void insertRenderBuffers(GLuint renderBuf) { m_renderbuffers.push_back(renderBuf);}
    void delTextures(GLuint tex) { m_textures.remove(tex);}
    void delBuffers(GLuint buf) {m_buffers.remove(buf);}
    void delFramebuffers(GLuint frameBuf) {m_framebuffers.remove(frameBuf);}
    void delRenderBufffers(GLuint renderBuf) {m_renderbuffers.remove(renderBuf);}
    void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct);
    void drawPointsArrs(GLESConversionArrays& arrs,GLint first,GLsizei count);
    void drawPointsElems(GLESConversionArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices);
    virtual const GLESpointer* getPointer(GLenum arrType);
    int  getMaxTexUnits();

    virtual bool glGetIntegerv(GLenum pname, GLint *params);
    virtual bool glGetBooleanv(GLenum pname, GLboolean *params);
    virtual bool glGetFloatv(GLenum pname, GLfloat *params);
    virtual bool glGetFixedv(GLenum pname, GLfixed *params);
  
    ~GLEScmContext();
protected:

    bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id);
private:
    void setupArrayPointerHelper(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLenum array_id,GLESpointer* p);
    void setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride,GLboolean normalized, int pointsIndex = -1);
    void drawPoints(PointSizeIndices* points);
    void drawPointsData(GLESConversionArrays& arrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices_in,bool isElemsDraw);
    void initExtensionString();

    GLESpointer*          m_texCoords;
    int                   m_pointsIndex;
    unsigned int          m_clientActiveTexture;
    std::list<GLuint >    m_textures;
    std::list<GLuint >    m_buffers;
    std::list<GLuint >    m_framebuffers;
    std::list<GLuint >    m_renderbuffers;
};